﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://www.codeplex.com/EmlenMud
using System.Runtime.Serialization;
using System;
using System.Xml.Serialization;
using System.Threading;
using System.Reflection;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BrainTechLLC.ThreadSafeObjects;

namespace BrainTechLLC
{
    public class SayCommand : Command, ICommandInfo
    {
        public override string HelpText { get { return "Say something that others in the room can hear"; } }
        public override string Example { get { return "say hello there... how goes it?"; } }

        [NonSerialized, XmlIgnore]
        public static List<string> Words = new List<string>() { "SAY" };

        public override List<string> FirstWords { get { return Words; } }

        public override bool CheckIsValid(IGameThing source, string first, string input)
        {
            if (string.IsNullOrEmpty(input))
                return false;

            return base.CheckIsValid(source, first, input);
        }

        [MethodVisible]
        public static List<PerceivedEventAndAudience> PerformMethod(CommandToPerform cmd, IGameThing source, IGameThing target, PropertyData args, PropertyData modifyingArguments)
        {
            List<PerceivedEventAndAudience> events = new List<PerceivedEventAndAudience>();
            GameThingBaseClass sourceChar = source as GameThingBaseClass;
            string allParams = (cmd.UserInput == null) ? string.Empty : cmd.UserInput;
            
            EventToPerceive evt = CreateObservable(source, allParams);
            events.Add(new PerceivedEventAndAudience() { Event = evt, Audience = sourceChar.GameLocation.Things });

            return events;
        }

        [MethodVisible]
        public static EventToPerceive CreateObservable(IAssociatedID source, string text)
        {
            return new GeneralEventToPerceive()
            {
                ShowToObservers = new Event(string.Format("~source says, '{0}'", text), ViewType.Hear),
                ShowToSource = new Event(string.Format("You say '{0}'", text), ViewType.Hear),
                Sources = new AssociatedIDCollection(source.AssociatedID)
            };
        }

    }
}
